package com.dgut.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.dgut.common.OrderType;
import com.dgut.common.SelectRole;
import com.dgut.pojo.OrderEvaluation;
import com.dgut.pojo.OrderFlag;
import com.dgut.service.*;
import com.dgut.utils.PageRequestInfo;
import com.dgut.pojo.Buyer;
import com.dgut.service.BuyerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

@Api(value = "BuyerController")
@RestController
@CrossOrigin
@RequestMapping("/buyer")
public class BuyerController {
    @Resource
    private OrderFlagService orderFlagService;
    @Resource
    private CompanyEstablishmentService companyEstablishmentService;
    @Resource
    private CompanyConversionService companyConversionService;
    @Resource
    private QualificationCertificateService qualificationCertificateService;
    @Resource
    private LegalRecourseService legalRecourseService;
    @Resource
    private AnnualReportService annualReportService;
    @Resource
    private InformationPublicityService informationPublicityService;
    @Resource
    private IntellectualPropertyService intellectualPropertyService;
    @Resource
    private OrderEvaluationService orderEvaluationService;
    /**
     * start-zwb
     */

    @SaCheckLogin
    @SaCheckRole(SelectRole.BUYER)
    @ApiOperation(value = "采买方获取订单表")
    @PostMapping("/getOrderList")
    public Object  getOrderList(@ApiParam(value = "分页信息",required = true) @RequestBody PageRequestInfo pageRequestInfo, @ApiParam(value = "类型",required = true) @RequestParam String type, @ApiParam(value = "状态",required = true) @RequestParam String state) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        map.put("orderList", orderFlagService.getOrderList(pageRequestInfo,type,state));
        return map;
    }
    @SaCheckLogin
    @ApiOperation(value = "查看订单详情")
    @PostMapping("/getOrder")
    public Object  getOrder(@ApiParam(value = "订单id",required = true) @RequestParam Integer id) {
        ConcurrentHashMap map = new ConcurrentHashMap();
        OrderFlag orderFlag = orderFlagService.getOrder(id);
        map.put("order", orderFlag);
        String type = orderFlag.getType();
        Integer typeId = orderFlag.getTypeId();
        if(OrderType.COMPANY_ESTABLISHMENT.equals(type))
            map.put("companyEstablishment",companyEstablishmentService.getCompanyEstablishment(typeId));
        else if(OrderType.COMPANY_CONVERSION.equals(type))
            map.put("companyConversion",companyConversionService.getCompanyConversionService(typeId));
        else if(OrderType.QUALIFICATION_CERTIFICATE.equals(type))
            map.put("qualificationCertificate",qualificationCertificateService.selectQualificationCertificateByIdForOrder(typeId));
        else if(OrderType.LEGAL_RECOURSE.equals(type))
            map.put("legalRecourse",legalRecourseService.getLegalRecourseById(typeId));
        else if(OrderType.ANNUAL_REPORT.equals(type))
            map.put("annualReport",annualReportService.getAnnualReport(typeId));
        else if(OrderType.INFO_PUBLICITY.equals(type))
            map.put("informationPublicity",informationPublicityService.getInformationPublicity(typeId));
        else if(OrderType.INTELLECTUAL_PROPERTY.equals(type))
            map.put("intellectualProperty",intellectualPropertyService.getIntellectualPropertyDetail(typeId));
        return map;
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.BUYER)
    @ApiOperation(value = "采买方申请取消订单")
    @PostMapping("/requestCancellationOfOrder")
    public Object  requestCancellationOfOrder(@ApiParam(value = "订单id",required = true) @RequestParam Integer id) {
        return orderFlagService.requestCancellationOfOrder(id);
    }
    @SaCheckLogin
    @SaCheckRole(SelectRole.BUYER)
    @ApiOperation(value = "采买方对订单付款")
    @PostMapping("/payForOrder")
    public Object  payForOrder(@ApiParam(value = "订单id",required = true) @RequestParam Integer id) {
        return orderFlagService.payForOrder(id);
    }

    @SaCheckLogin
    @SaCheckRole(SelectRole.BUYER)
    @ApiOperation(value = "采买方对订单确认")
    @PostMapping("/confirmForOrder")
    public Object  confirmForOrder(@ApiParam(value = "订单id",required = true) @RequestParam Integer id) {
        return orderFlagService.confirmOrder(id);
    }


    @SaCheckLogin
    @SaCheckRole(SelectRole.BUYER)
    @ApiOperation(value = "采买方添加订单评价")
    @PostMapping("/addOrderEvaluation")
    public Object  addOrderEvaluation(@ApiParam(value = "订单服务信息",required = true) @RequestBody OrderEvaluation orderEvaluation) {
        return orderEvaluationService.addOrderEvaluation(orderEvaluation);
    }


    /**
     * end-zwb
     */


    @Resource
    private BuyerService buyerService;

    @ApiOperation(value = "查看采买方账户基本信息",notes = "")
    @GetMapping("/checkPersonalInformation")
    public Object checkPersonalInformation(@ApiParam(value = "传采买方的id",required = true)
                                           @RequestParam Integer id){
        return buyerService.CheckPersonalInformation(id);
    }

    @ApiOperation(value = "采买方修改账户基本信息",notes = "")
    @PostMapping("/updatePersonalInformation")
    public Object updatePersonalInformation(@ApiParam(value = "传采买方实体类",required = true)
                                            @RequestBody Buyer buyer){
        return buyerService.UpdatePersonalInformation(buyer);
    }
}
